<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>

<%@ page import="java.util.List" %>
<%@ page import="com.xingyue.loginqueryarticle.Dao.PageDao" %>
<%@ page import="javax.management.Query" %>
<%@ page import="com.xingyue.loginqueryarticle.Dao.QueryDao" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>list</title>
    <link href="static/dist/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<div style="width: 600px;margin: 10% auto">
    <table class="table table-bordered table-hover">
        <thead>
        <tr><th>id</th><th>name</th><th>password</th><th>option</th></tr>
        </thead>
        <tbody>
        <%    //传递要显示的页数
            String pagestr =request.getParameter("page");

            int currentPage=1;    //初始显示在的页数
            //字符串 强转int 可能会出现异常
            try {
                currentPage = Integer.valueOf(pagestr); //当前在的这一页
            }catch (Exception e) {
            }
            QueryDao dao = new QueryDao();
            //
            PageDao pgd=dao.queryPage(currentPage);

            List<JSONObject> lis=pgd.getData();//调用集合列表

            for(int i=0;i<lis.size();i++){  //循环遍历集合
                JSONObject object = (JSONObject) lis.get(i);  //


        %>
        <tr>
            <td><%=object.getString("id")%></td>
            <td><%=object.getString("name")%></td>
            <td><%=object.getString("password")%></td>

            <td>
                <%--
                    1.点击修改,跳转到EditorController,去重新查询一遍数据
                    2.查询出来之后再跳转editor.jsp
                --%>
                <a href="editor?id=<%=object.getString("id")%>" class="btn btn-info">修改</a>
                <a href="delete?id=<%=object.getString("id")%>" class="btn btn-warning">删除</a>
            </td>
        </tr>
        <%
            }
        %>

        </tbody>
    </table>
    <nav>
        <ul class="pagination pagination-lg">
            <%
                if(pgd.getCurrentPage()>1){
                    //是否是第一页, 显示上一页
                    int lastPage =pgd.getCurrentPage()-1;
            %>
            <li><a href="Page.jsp?page=<%=lastPage%>" ><%=lastPage%></a></li>
            <%
                }
            %>
            <li class="active" ><a href="Page.jsp?page=<%=pgd.getCurrentPage()%>" > <%=pgd.getCurrentPage()%> </a> </li>
            <%
                //最大显示页签数
                int tagLimit =3;
                for(int i=pgd.getCurrentPage()+1; i<=pgd.getTotalPage();i++){
                    tagLimit--;
                    if(tagLimit<0)break;
            %>
            <li> <a href="Page.jsp?page=<%=i%>"><%=i%></a> </li>
            <%
                }
            %>
        </ul>
    </nav>

</div>
</body>
</html>

